{% extends "base_en.html" %}

{% block title %}
	{%if user %}
		Projektliste
	{%else%}
		Startseite
	{%endif%}
{% endblock %}

{% block head %}
	{%if user %}
		<script type="text/javascript">
			function project_DeleteClick(key)
			{
				new Ajax.Request("/", {
					method: 'post',
					parameters: {
						action: 'delete',
						token: key,
					},
					onSuccess: function(transport)
					{
						location.href=transport.responseText;
					},
					onFailure: function(transport)
					{
						alert(transport.responseText);
					}
				});
				return false;
			}

			function project_AddClick(event)
			{
				new Ajax.Request("/", {
					method: 'post',
					parameters: {
						action: 'add',
						name: $F('project_name'),
						currency: $F('project_currency'),
					},
					onSuccess: function(transport)
					{
						location.href=transport.responseText;
					},
					onFailure: function(transport)
					{
						alert(transport.responseText);
					}
				});
				return false;
			}
		</script>
	{%endif%}
{% endblock %}

{% block buttons %}
<span class="item">
</span>
{% endblock %}

{% block body %}
	{% if message %}{{ message }}{% endif %}
	<ul>
	{% for token in tokens %}
		<li>{{ token.DisplayName }}
			<a href="/summary?token={{ token.Token }}">[Report]</a>&nbsp;
			{%if token.RightEdit %}
				<a href="/transactions?token={{ token.Token }}">[Transaktionen]</a>&nbsp;
				<a href="/accounts?token={{ token.Token }}">[Konten]</a>&nbsp;
				<a href="/currencies?token={{ token.Token }}">[Währungen]</a>&nbsp;
			{%endif%}
			{%if token.RightManage %}
				<a href="/access?token={{ token.Token }}">[Zugriff/Einladungen]</a>&nbsp;
			{%endif%}
			{%if token.RightView %}
				<a href="/projectsettings?token={{ token.Token }}">[Einstellungen]</a>&nbsp;
			{%endif%}
			{%if token.last_access %}
				<button id="project_remove" type="submit" name="Action" value="Delete" onclick="project_DeleteClick('{{ token.Token}}')">Projekt löschen</button>
			{%else%}
				<button id="project_remove" type="submit" name="Action" value="Delete" onclick="project_DeleteClick('{{ token.Token }}')">Projekt aus meiner Liste entfernen</button>
			{%endif%}
		</li>
	{% endfor %}
	</ul>
	{%if user %}
		<form id="newProjectForm" enctype="multipart/form-data" onsubmit="return false;">
			<fieldset>
				<legend>Neues Projekt anlegen...</legend>
				<label for="project_name">Name</label>
				<input id="project_name" type="text" name="TEXT" size="20" VALUE=""/>
				<br/>

				<label for="project_currency">Grundwährung</label>
				<input id="project_currency" type="text" name="TEXT" size="5" VALUE="€"/>
				<br/>

				<label for="project_add">Projekt</label>
				<button id="project_add" type="submit" name="Action" value="Add" onclick="project_AddClick()">Erstellen...</button>
			</fieldset>
		</form>
	{%else%}
		<p>Um die Urlaubsabrechnung nutzen zu können, musst Du Dich <a href="{{ login_url|escape }}">anmelden</a>!</p>
	{%endif%}
	{% if adminTokens %}
	<h1>Adminzugriff</h1>
		{% for token in adminTokens %}
			<li>{{ token.DisplayName }}
				<a href="/summary?token={{token.Token}}">[Report]</a>&nbsp;
				<a href="/transactions?token={{token.Token}}">[Transaktionen]</a>&nbsp;
				<ul>
					{% for access in token.project.projectaccess_set %}
					<li>{{access.UserName}} &rArr; {{access.right}}</li>
					{% endfor %}
				</ul>
			</li>
		{% endfor %}
	{% endif %}
{% endblock %}
